package com.oil.petro.eshop.controller;

import com.oil.petro.eshop.bean.BasicBean;
import com.oil.petro.eshop.bean.CredentialBean;
import com.oil.petro.eshop.bean.UserBean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class LoginController {
    
    
     @RequestMapping(value = "/test2", method = RequestMethod.GET)
    public ModelAndView signIn() {
       // Person person = new Person("Marcin", "Cichonski", "99-300", "Gandhiego", "Łódź");
       // Account account = new Account("login4", "password4", "email4", 1);
       
        
        //userAccountService.saveUser(userBean);
              
        
        
        
        System.out.println("logowanie post");
     Map<String, Object> model = new HashMap<String, Object>();
       //  model.put("person", person);
       //  model.put("account", account);
//        model.put("email", account.getEmail());
//         model.put("login", account.getLogin());
//          model.put("password", account.getPassword());
//        model.put("firstname", person.getFirstName());
//         model.put("lastname", person.getLastName());
//          model.put("city", person.getCity());
//            model.put("address", person.getAddress());
//            model.put("postcode", person.getPostCode());
        return new ModelAndView("account/test",model);

    }
    
    
       @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ModelAndView signIn2(@RequestParam(value = "error", required = false) String error) {
       // Person person = new Person("Marcin", "Cichonski", "99-300", "Gandhiego", "Łódź");
       // Account account = new Account("login4", "password4", "email4", 1);
       
        
        //userAccountService.saveUser(userBean);
              
        
        
        
        System.out.println("logowanie post");
     Map<String, Object> model = new HashMap<String, Object>();
       //  model.put("person", person);
       //  model.put("account", account);
//        model.put("email", account.getEmail());
//         model.put("login", account.getLogin());
//          model.put("password", account.getPassword());
//        model.put("firstname", person.getFirstName());
//         model.put("lastname", person.getLastName());
//          model.put("city", person.getCity());
//            model.put("address", person.getAddress());
//            model.put("postcode", person.getPostCode());
        return new ModelAndView("account/loginPage",model);

    }
    
    
//    @RequestMapping("/login")
//    public ModelAndView registerUser() {
//       // Person person = new Person("Marcin", "Cichonski", "99-300", "Gandhiego", "Łódź");
//       // Account account = new Account("login4", "password4", "email4", 1);
//       
//     Map<String, Object> model = new HashMap<String, Object>();
//       //  model.put("person", person);
//       //  model.put("account", account);
////        model.put("email", account.getEmail());
////         model.put("login", account.getLogin());
////          model.put("password", account.getPassword());
////        model.put("firstname", person.getFirstName());
////         model.put("lastname", person.getLastName());
////          model.put("city", person.getCity());
////            model.put("address", person.getAddress());
////            model.put("postcode", person.getPostCode());
//        return new ModelAndView("signinPage", model);
//
//    }
    
////    @RequestMapping(value = "/login", method = RequestMethod.POST)
////    public ModelAndView signInSubmit(@ModelAttribute("commandBean") BasicBean basicBean) {
////       // Person person = new Person("Marcin", "Cichonski", "99-300", "Gandhiego", "Łódź");
////       // Account account = new Account("login4", "password4", "email4", 1);
////       
////        
////        //userAccountService.saveUser(userBean);
////              
////        
////        
////        
////        System.out.println("logowanie post");
////     Map<String, Object> model = new HashMap<String, Object>();
////       //  model.put("person", person);
////       //  model.put("account", account);
//////        model.put("email", account.getEmail());
//////         model.put("login", account.getLogin());
//////          model.put("password", account.getPassword());
//////        model.put("firstname", person.getFirstName());
//////         model.put("lastname", person.getLastName());
//////          model.put("city", person.getCity());
//////            model.put("address", person.getAddress());
//////            model.put("postcode", person.getPostCode());
////        return new ModelAndView("product/productList",model);
////
////    }
    
   
    public ModelAndView loginUser(@ModelAttribute("credentialBean") CredentialBean  credentialBean) {
       // Person person = new Person("Marcin", "Cichonski", "99-300", "Gandhiego", "Łódź");
        // Account account = new Account("login4", "password4", "email4", 1);

        List<String> categroyList = new ArrayList<String>();
        
        categroyList.add("Monitory");
        categroyList.add("Komputery");
        categroyList.add("Laptopy");
        categroyList.add("Myszki");
        categroyList.add("Klawiatury");
        categroyList.add("Drukarki");
        categroyList.add("Dyski");
        categroyList.add("Akcesoria");
        categroyList.add("Głosniki");
        Map<String, Object> model = new HashMap<String, Object>();
 
        //czy uzytkownik do administrator czy moze normalny user
        model.put("status",1);
        model.put("menu", categroyList);
        return new ModelAndView("product/productList", model);

    }
    
    
}
